<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue.js"></script>
</head>
<template id="cpn_id">
    <div>
        <button v-for="(item,index) in categories" v-on:click="btnClick(item)">{{item.value}}</button>
    </div>
</template>
<body>
<div id="div_id">
    <!--使用v-on监听子组件发送的事件-->
    <cpn1 v-on:itemClick="cpnClick"></cpn1>
</div>
<script>
    const cpn1={
        template:"#cpn_id",
        data(){
            return{
                categories:[
                    {id:1,value:'目录1'},
                    {id:2,value:'目录2'},
                    {id:3,value:'目录3'},
                    {id:4,value:'目录4'},
                ]
            }
        },
        methods:{
            btnClick(item){
                //向父组件发送事件
                this.$emit("itemclick",item);
            }
        }
    };
    const app=new Vue({
        el:"#div_id",
        components:{
            cpn1
        },
        methods: {
            cpnClick(item){
                console.log("cpnClick");
                console.log(item);

            }
        }
    })
</script>
</body>
</html>